using System.ComponentModel.DataAnnotations;

namespace Lzfy_Refund_Service.Models
{
    public class Role
    {
        public int Id { get; set; }
        public DateTime InputDate { get; set; } = DateTime.Now;
        
        [Required(ErrorMessage = "角色名称不能为空")]
        [StringLength(50, ErrorMessage = "角色名称长度不能超过50个字符")]
        public string RoleName { get; set; } = string.Empty;
        
        [Required(ErrorMessage = "角色编码不能为空")]
        [StringLength(50, ErrorMessage = "角色编码长度不能超过50个字符")]
        public string RoleCode { get; set; } = string.Empty;
        
        [StringLength(200, ErrorMessage = "角色描述长度不能超过200个字符")]
        public string? Description { get; set; }
        
        public bool IsActive { get; set; } = true;
        public int SortOrder { get; set; } = 0;
    }
    
    public class Menu
    {
        public int Id { get; set; }
        public DateTime InputDate { get; set; } = DateTime.Now;
        
        [Required(ErrorMessage = "菜单名称不能为空")]
        [StringLength(50, ErrorMessage = "菜单名称长度不能超过50个字符")]
        public string MenuName { get; set; } = string.Empty;
        
        [Required(ErrorMessage = "菜单编码不能为空")]
        [StringLength(50, ErrorMessage = "菜单编码长度不能超过50个字符")]
        public string MenuCode { get; set; } = string.Empty;
        
        public int? ParentId { get; set; }
        
        [StringLength(10, ErrorMessage = "菜单类型长度不能超过10个字符")]
        public string MenuType { get; set; } = "menu";
        
        [StringLength(200, ErrorMessage = "路由路径长度不能超过200个字符")]
        public string? Path { get; set; }
        
        [StringLength(200, ErrorMessage = "组件路径长度不能超过200个字符")]
        public string? Component { get; set; }
        
        [StringLength(50, ErrorMessage = "图标长度不能超过50个字符")]
        public string? Icon { get; set; }
        
        public int SortOrder { get; set; } = 0;
        public bool IsActive { get; set; } = true;
        public bool IsVisible { get; set; } = true;
        
        [StringLength(100, ErrorMessage = "权限标识长度不能超过100个字符")]
        public string? Permission { get; set; }
        
        [StringLength(200, ErrorMessage = "描述长度不能超过200个字符")]
        public string? Description { get; set; }
    }
    
    public class UserRole
    {
        public int Id { get; set; }
        public DateTime InputDate { get; set; } = DateTime.Now;
        public int UserId { get; set; }
        public int RoleId { get; set; }
    }
    
    public class RoleMenu
    {
        public int Id { get; set; }
        public DateTime InputDate { get; set; } = DateTime.Now;
        public int RoleId { get; set; }
        public int MenuId { get; set; }
    }
    
    // DTO 类
    public class RoleDto
    {
        public int Id { get; set; }
        public string RoleName { get; set; } = string.Empty;
        public string RoleCode { get; set; } = string.Empty;
        public string? Description { get; set; }
        public bool IsActive { get; set; }
        public int SortOrder { get; set; }
        public DateTime InputDate { get; set; }
    }
    
    public class MenuDto
    {
        public int Id { get; set; }
        public string MenuName { get; set; } = string.Empty;
        public string MenuCode { get; set; } = string.Empty;
        public int? ParentId { get; set; }
        public string MenuType { get; set; } = string.Empty;
        public string? Path { get; set; }
        public string? Component { get; set; }
        public string? Icon { get; set; }
        public int SortOrder { get; set; }
        public bool IsActive { get; set; }
        public bool IsVisible { get; set; }
        public string? Permission { get; set; }
        public string? Description { get; set; }
        public List<MenuDto>? Children { get; set; }
    }
    
    public class UserDto
    {
        public int Id { get; set; }
        public string Username { get; set; } = string.Empty;
        public string FullName { get; set; } = string.Empty;
        public string? Email { get; set; }
        public string? Phone { get; set; }
        public bool IsActive { get; set; }
        public DateTime InputDate { get; set; }
        public DateTime? LastLoginDate { get; set; }
        public DateTime CreatedAt { get; set; }
        public DateTime? LastLoginAt { get; set; }
        public List<string>? RoleNames { get; set; }
        public List<RoleDto>? Roles { get; set; }
    }
    
    public class UserRoleDto
    {
        public int Id { get; set; }
        public int UserId { get; set; }
        public string Username { get; set; } = string.Empty;
        public string FullName { get; set; } = string.Empty;
        public int RoleId { get; set; }
        public string RoleName { get; set; } = string.Empty;
        public string RoleCode { get; set; } = string.Empty;
        public DateTime InputDate { get; set; }
    }
    
    // 请求/响应模型
    public class RoleListRequest
    {
        public int Page { get; set; } = 1;
        public int PageSize { get; set; } = 10;
        public string? RoleName { get; set; }
        public string? RoleCode { get; set; }
        public bool? IsActive { get; set; }
    }
    
    public class RoleListResponse
    {
        public List<RoleDto> Roles { get; set; } = new();
        public int Total { get; set; }
        public int Page { get; set; }
        public int PageSize { get; set; }
    }
    
    public class MenuTreeRequest
    {
        public string? MenuName { get; set; }
        public bool? IsActive { get; set; }
        public bool? IsVisible { get; set; }
    }
    
    public class RolePermissionRequest
    {
        public int RoleId { get; set; }
        public List<int> MenuIds { get; set; } = new();
    }
    
    public class AssignPermissionRequest
    {
        public int RoleId { get; set; }
        public List<int> MenuIds { get; set; } = new();
        public int TargetId { get; set; }
        public string Type { get; set; } = "role"; // "role" 或 "user"
    }
    
    public class UserListRequest
    {
        public int Page { get; set; } = 1;
        public int PageSize { get; set; } = 10;
        public string? Username { get; set; }
        public string? FullName { get; set; }
        public int? RoleId { get; set; }
        public bool? IsActive { get; set; }
    }
    
    public class UserListResponse
    {
        public List<UserDto> Users { get; set; } = new();
        public int Total { get; set; }
        public int Page { get; set; }
        public int PageSize { get; set; }
    }
    
    public class ToggleStatusRequest
    {
        public int Id { get; set; }
        public bool IsActive { get; set; }
    }
}